import { Injectable } from '@nestjs/common';
import { Result } from '../../common/result/Result';
import { PageResult } from '../../common/result/PageResult';
import { U9Repository } from '../../config/U9.module';
import { Repository } from 'typeorm';
import { IBaseEntity } from '../00_base/IBaseEntity';
import { InjectRepository } from '@nestjs/typeorm';

@Injectable()
export class FakeService {
  constructor(
    @InjectRepository(IBaseEntity)
    private baseRepository: Repository<IBaseEntity>, // mysql数据库连接工具
  ) {}

  /**
   * U9列表查询
   * @param sql
   */
  async queryU9ListService(sql: string) {
    return Result.success(await U9Repository.query(sql));
  }

  /**
   * U9分页查询
   * @param sql
   * @param countSql
   */
  async queryU9PageService(sql: string, countSql: string) {
    return PageResult.success(
      await U9Repository.query(sql),
      await U9Repository.query(countSql),
    );
  }

  /**
   * U9增加内容
   * @param sql
   */
  async addU9ColumnService(sql: string) {
    return Result.success(await U9Repository.query(sql));
  }

  /**
   * U9修改表内容
   * @param sql
   */
  async updateU9ColumnService(sql: string) {
    return Result.success(await U9Repository.query(sql));
  }

  /**
   * U9修改表内容
   * @param sql
   */
  async deleteU9ColumnService(sql: string) {
    return Result.success(await U9Repository.query(sql));
  }

  /**
   * 分页查询
   * @param sql
   * @param countSql
   */
  async queryPageService(sql: string, countSql: string) {
    return PageResult.success(
      await this.baseRepository.query(sql),
      await this.baseRepository.query(countSql),
    );
  }

  /**
   * 列表查询
   * @param sql
   */
  async queryListService(sql: string) {
    return Result.success(await this.baseRepository.query(sql));
  }

  /**
   * 修改
   * @param sql
   */
  async updateService(sql: string) {
    return Result.success(await this.baseRepository.query(sql));
  }

  /**
   * 软删除
   * @param query
   */
  async softDeleteService(query: any) {
    return Result.success(await this.baseRepository.softDelete(query));
  }

  /**
   * 物理删除
   * @param sql
   */
  async deleteService(sql: string) {
    return Result.success(await this.baseRepository.query(sql));
  }
}
